/*
 * @Copyright: Copyright (c) 2030 吴周海
 * @Author: wzh200x@126.com
 * @Date: 2025-10-13 14:01:41
 * @LastEditors: wzh200x@126.com
 * @LastEditTime: 2025-10-13 15:42:00
 * @FilePath: \gogamewebserver\goGameWebServer\internal\controller\auth\auth_v1_private.go
 * @Description: 文件功能描述
 */
package auth

import (
	"context"
	v1 "goGameWebServer/api/auth/v1"
	"goGameWebServer/internal/controller"
	"goGameWebServer/internal/defines/cerror"
	"goGameWebServer/internal/jwt"

	"github.com/gogf/gf/v2/frame/g"
)

func (c *AuthControllerV1Private) UpdateToken(context context.Context, req *v1.AuthUpdateTokenReq) (res *v1.AuthUpdateTokenRes, err error) {
	// 查询账号信息
	r := g.RequestFromCtx(context)
	uid := r.GetParam("userID").Uint()
	uName := r.GetParam("username").String()
	res = &v1.AuthUpdateTokenRes{}
	jwtToken, tokenExpireTime, e := jwt.GenerateToken(uint(uid), uName)
	if e != nil {
		controller.BackResponseError(g.RequestFromCtx(context), cerror.HTTP_TOKEN_INVALID_ERROR, e.Error())
		return
	}
	res.AccessToken = jwtToken
	res.TokenExpireTime = tokenExpireTime
	controller.BackResponseOK(g.RequestFromCtx(context), res)
	// }
	return
}
